'''
Created on 2010-12-14

@author: Administrator
'''

import wx

class RefactorFrame(wx.Frame):
  def __init__(self, parent, id):
    wx.Frame.__init__(self, parent, id, 'Refactor Example', size=(340,200))
    panel = wx.Panel(self, -1)
    panel.SetBackgroundColour('white')
    
    # Create Buttons
    self.createButtonBar(panel)
    # Create Menu
    self.createMenuBar()
    # Create Text
    self.createTextFields(panel)
    
    self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
    
    
  def buttonData(self):
    '''
      Button Name And Handler
    '''
    return (("First", self.OnFirst), ("<< Prev", self.OnPrev),
            ("Next >>", self.OnNext),("Last", self.OnLast))
  
  def createButtonBar(self, panel, yPos=0):
    """ Loop Create Button"""
    xPos = 0
    for eachLabel, eachHandler in self.buttonData():
      pos = (xPos, yPos)
      button = self.buildOneButton(panel, eachLabel, eachHandler, pos)
      xPos += button.GetSize().width
    
  def buildOneButton(self, parent, label, handler, pos=(0,0)):
    """ Create One Button """
    button = wx.Button(parent, -1, label, pos)
    self.Bind(wx.EVT_BUTTON, handler, button)
    return button
  
  def menuData(self):
    """ Menu Labels And Handler"""
    return (("&File",("&Open", "Open In the Status Bar", self.OnOpen),
                     ("&Quit", "Quit", self.OnCloseWindow)),
            ("&Edit",("&Copy", "Copy", self.OnCopy),
                     ("&Cut", "Cut", self.OnCut),
                     ("&Paste", "Paste", self.OnPaste),
                     ("", "", ""),
                     ("&Option", "Display Option", self.OnOptions)))
  
  def createMenuBar(self):
    menuBar = wx.MenuBar()
    for eachMenuData in self.menuData():
      menuLabel = eachMenuData[0]
      menuItems = eachMenuData[1:]
      menuBar.Append(self.createMenu(menuItems), menuLabel)
    self.SetMenuBar(menuBar)
  
  def createMenu(self, menuData):
    menu = wx.Menu()
    for eachLabel, eachStatus, eachHandler in menuData:
      if not eachLabel:
        menu.AppendSeparator()
        continue
      menuItem = menu.Append(-1, eachLabel, eachStatus)
      self.Bind(wx.EVT_MENU, eachHandler, menuItem)
    return menu
  
  def textFieldData(self):
    return (("First Name", (10, 50)),
            ("Last Name", (10, 80)))
  
  def createTextFields(self, panel):
    for eachLabel, eachPos in self.textFieldData():
      self.createCaptionedText(panel, eachLabel, eachPos)
    
  def createCaptionedText(self, panel, label, pos):
    static = wx.StaticText(panel, wx.NewId(), label, pos)
    static.SetBackgroundColour("White")
    textPos = (pos[0] + 75, pos[1])
    wx.TextCtrl(panel, wx.NewId(), "", size=(100,-1), pos=textPos)
    
  
  def OnFirst(self, event): pass
  def OnPrev(self, event): pass
  def OnNext(self, event): pass
  def OnLast(self, event): pass
  def OnOpen(self, event): pass
  
  def OnCopy(self, event): pass
  def OnCut(self, event): pass
  def OnPaste(self, event): pass
  def OnOptions(self, event): pass
  
  def OnQuit(self, event): 
    self.Close()
  
  def OnCloseWindow(self, event):
    self.Destroy()

if __name__ == '__main__':
  app = wx.PySimpleApp()
  frame = RefactorFrame(None, -1)
  frame.Show()
  app.MainLoop()
